/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package jse;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Random;

/**
 *
 * @author WangShuai
 */
public class CollectionSort {

    public static void main(String[] args) {
        List list = new ArrayList();
        Random r = new Random();
        for (int i = 0; i < 20; i++) {
            list.add(r.nextInt(100));
        }
        for (Object o : list) {
            System.out.print(o + " , ");
        }

        //Collections.sort(list);
        //Collections.shuffle(list);
        //Collections.reverse(list);   

        Collections.sort(list, new Comparator(){

            public int compare(Object o1, Object o2) {
                Integer i1 = (Integer)o1;
                Integer i2 = (Integer)o2;
                //return -i1.compareTo(i2);   //From big to small
                return i1.compareTo(i2);   //From small  to big
            }

        });
        System.out.println("\nAfter:");
        for (Object o : list) {
            System.out.print(o + " , ");
        }

    }
}
